<?php
/**
 * Created by PhpStorm.
 * User: aron
 * Date: 2019/6/28
 * Time: 4:54 PM
 */

include_once "../../../Util/DebugUtil/DebugUtil.php";

class BanchMarkObject {
    var $label;
    var $totaltime;
    var $avgtime;
    var $list;
}

function banckMark($fileName) {
    $list = array();
    $oldDataStr = file_get_contents($fileName);
    $datas = explode("\n", $oldDataStr);
//    print_r($datas);
    $totalTime = 0;
    foreach ($datas as $data) {
        $startPos = strrpos($data, " = ") + 3;
        $timeStr = substr($data, $startPos);
        $list[] = $timeStr;
        $time = floatval($timeStr);
        $totalTime += $time;
    }
    $avgTime = $totalTime / count($datas);

    $obj = new BanchMarkObject();
    $obj->label = $fileName . "avgTime = ". $avgTime;
    $obj->list = $list;
    $obj->avgtime = $avgTime;
    $obj->totaltime = $totalTime;

    return $obj;
}

$results = array();

$results[] = banckMark("old.data");
$results[] = banckMark("new.data");

$json = json_encode($results);
echo $json;
